package com.lighthouse.base.common.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.lighthouse.base.common.dao.generalDAO;
import com.lighthouse.base.common.vo.SimpleVO;


@Service("SimpleService")
public class SimpleServiceImpl implements SimpleService{
	protected Log log = LogFactory.getLog(this.getClass());
	
    @Resource (name = "generalDao")
    generalDAO generalDao;
    
	public int getInfo() {
		int nInfoValue = -1;
		List<SimpleVO> simpleVoList = new ArrayList<SimpleVO>();
		SimpleVO simpleVo = new SimpleVO();
		
		try {
			simpleVo.setId(10);
			
			simpleVoList = generalDao.select("simplemanager_searchList", simpleVo);
			if((simpleVoList!=null)&&(simpleVoList.size()>0)) nInfoValue = simpleVoList.get(0).getDepth();
			
			if(log.isDebugEnabled()) log.debug(String.format("getInfo, return:%d", nInfoValue));
		}
		catch(Exception e){
			if(log.isDebugEnabled()) log.debug(String.format("[getInfo]:%s",e.toString()));
		}
		finally {
			simpleVoList = null;
			simpleVo = null;
		}
		return nInfoValue;
	}
	
	public List<SimpleVO> getSimpleList() {
		List<SimpleVO> simpleVoList = null;
		SimpleVO simpleVo = new SimpleVO();
		
		try {
			simpleVo.setId(10);
			simpleVoList = generalDao.select("simplemanager_searchList", simpleVo);
			if(log.isDebugEnabled()) log.debug(String.format("getSimpleList, return:%d", simpleVoList==null?-1:simpleVoList.size()));
		}
		catch(Exception e){
			if(log.isDebugEnabled()) log.debug(String.format("[getSimpleList]:%s",e.toString()));
		}
		finally {
			simpleVo = null;
		}
		return simpleVoList;
	}
	
	public int getInfoByMap() {
		Map<String, Object> map = new HashMap<String, Object>(); 
		List<SimpleVO> simpleVoList = null;
		
		try {
			map.put("id", 10);
			simpleVoList = generalDao.select("simplemanager_searchList_map", map);
			if(log.isDebugEnabled()) log.debug(String.format("getSimpleList, return:%d", simpleVoList==null?-1:simpleVoList.size()));
		}
		catch(Exception e){
			if(log.isDebugEnabled()) log.debug(String.format("[getSimpleList]:%s",e.toString()));
		}
		finally {
			map = null;
		}
		return simpleVoList.size();
	}
}
